// pages/vant-demo/vant-demo.js
import Toast from '@vant/weapp/toast/toast';
import Notify from '@vant/weapp/notify/notify';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        show: false,
        show2: false,
        show3: false,
        checked: true,
        checkedSwitch: true,
        valueField: 'lk的值',
        radio: '1',
        date: '',
        valueSearch: '',
        fileList: [{
            url: 'https://img.yzcdn.cn/vant/leaf.jpg',
            name: '图片1',
            status: 'done',
            deletable: true,
        }, ],
    },

    afterRead(event) {
        const {
            file
        } = event.detail;
        console.log(11, file);
        this.setData({
            fileList: [...this.data.fileList, {
                url: file.path,
                name: 'xx',
                deletable: true,
            }]
        });

    },
    onChangeSwitch({
        detail
    }) {
        // 需要手动对 checked 状态进行更新
        this.setData({
            checkedSwitch: detail
        });
    },
    onChangeRadio(event) {
        console.log(1, event);
        this.setData({
            radio: event.detail,
        });
    },
    onChangeField(event) {
        // event.detail 为当前输入的值
        console.log(event.detail);
    },
    onChange(event) {
        this.setData({
            checked: event.detail,
        });
    },
    onDisplay() {
        this.setData({
            show3: true
        });
    },
    onCloseDate() {
        this.setData({
            show3: false
        });
    },
    formatDate(date) {
        date = new Date(date);
        return `${date.getMonth() + 1}/${date.getDate()}`;
    },
    onConfirmDate(event) {
        this.setData({
            show3: false,
            date: this.formatDate(event.detail),
        });
    },

    showToast() {
        // wx.showToast({
        //   title: 'LKLK',
        // })
        const toast = Toast.loading({
            duration: 0, // 持续展示 toast
            forbidClick: true,
            message: '倒计时 3 秒',
            selector: '.custom-selector',
            mask: true,
            onClose: () => {
                console.log('执行OnClose函数');
            },
        });

        let second = 3;
        const timer = setInterval(() => {
            second--;
            if (second) {
                toast.setData({
                    message: `倒计时 ${second} 秒`,
                });
            } else {
                clearInterval(timer);
                Toast.clear();
            }
        }, 1000);
    },

    showPopup() {
        this.setData({
            show: true
        });
    },
    showPopup2() {
        console.log(11);
        this.setData({
            show2: true
        });
        setTimeout(() => {
            this.setData({
                show2: false
            });
        }, 3000);
    },

    onClose() {
        this.setData({
            show: false
        });
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        Notify({
            type: 'success',
            message: '通知内容'
        });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
            console.log('onShareAppMessage');
    }
})